/*
 * Filename    : Utils.java
 * Projectname : Sound Of Indonesia
 * Date        : Nov 1, 2012 , 12:10:49 PM 
 * 
 * PratamaNurWijaya
 */

package id.pratama.soundofindonesia;

import id.pratama.soundofindonesia.apps.Apps_Config;
import id.pratama.soundofindonesia.apps.Apps_Data;
import id.pratama.soundofindonesia.apps.Apps_Define;

import org.andengine.engine.camera.hud.HUD;
import org.andengine.entity.sprite.Sprite;
import org.andengine.opengl.texture.TextureOptions;
import org.andengine.util.debug.Debug;

public class Utils implements Apps_Define, Apps_Data
{

	public static float getRatio(float nil)
	{
		float nil_Ratio = 0;

		switch (Apps_Config.RATIO_USE)
		{
			case RATIO_WIDTH:
				nil_Ratio = nil / RATIO_RES_WIDTH * RES_WIDTH;
				break;
			case RATIO_HEIGHT:
				nil_Ratio = nil / RATIO_RES_HEIGHT * RES_HEIGHT;
				break;
		}

		return nil_Ratio;
	}

	public static float getRatioW(float nil)
	{
		return nil / RATIO_RES_WIDTH * RES_WIDTH;
	}

	public static float getRatioH(float nil)
	{
		return nil / RATIO_RES_HEIGHT * RES_HEIGHT;
	}

	public static TextureOptions getTextureOption()
	{
		return Apps_Config.AA_ENABLE ? TextureOptions.REPEATING_BILINEAR : TextureOptions.REPEATING_NEAREST;
	}

	public static void TRACE(String arg)
	{
		if (Apps_Config.TRACE)
		{
			System.out.println(arg);
		}
	}

	public static void DEBUG(Exception arg)
	{
		if (Apps_Config.DEBUG)
		{
			Debug.e(arg);
		}
	}

	public static boolean isOnArea(float p_X, float p_Y, Sprite p_Shape)
	{
		return isOnArea(p_X, p_Y, p_Shape.getX(), p_Shape.getX() + p_Shape.getWidth(), p_Shape.getY(), p_Shape.getY()
				+ p_Shape.getHeight());
	}

	public static boolean isOnArea(float p_X, float p_Y, Sprite p_ShapeParent, Sprite p_Shape)
	{
		return isOnArea(p_X, p_Y, p_ShapeParent.getX() + p_Shape.getX(), p_ShapeParent.getX() + p_Shape.getX()
				+ p_Shape.getWidth(), p_ShapeParent.getY() + p_Shape.getY(), p_ShapeParent.getY() + p_Shape.getY()
				+ p_Shape.getHeight());
	}

	public static boolean isOnArea(float p_X, float p_Y, HUD p_ShapeParent, Sprite p_Shape)
	{
		return isOnArea(p_X, p_Y, p_ShapeParent.getX() + p_Shape.getX(), p_ShapeParent.getX() + p_Shape.getX()
				+ p_Shape.getWidth(), p_ShapeParent.getY() + p_Shape.getY(), p_ShapeParent.getY() + p_Shape.getY()
				+ p_Shape.getHeight());
	}

	public static boolean isOnArea(float p_X, float p_Y, float p_MinX, float p_MaxX, float p_MinY, float p_MaxY)
	{
		if (p_X > p_MinX && p_X < p_MaxX && p_Y > p_MinY && p_Y < p_MaxY)
			return true;

		return false;
	}
}
